package com.sphd.Restaurant.presenter;

import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.infos.MsgsInfo;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.JsonUtil;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.MsgView;


import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/10/17.
 */

public class MsgP extends BasePresenter implements VolleyCallBack<JSONObject> {
    MsgView msgView;

    public MsgP(MsgView msgView) {
        this.msgView = msgView;
    }

    @Override
    public void addData(String url) {

            sendJsonObjectUrl(url,this);
    }

    @Override
    public void onResponse(JSONObject object) {
        try {
            List<MsgsInfo> msgsInfoList= JsonUtil.getListFromString(object.getString("res"),MsgsInfo.class);
            msgView.sendRes(msgsInfoList);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();
    }
}
